package com.weixin.project.Specification;

import com.weixin.project.Entity.Question;
import org.springframework.data.jpa.domain.Specification;

public class QuestionSpecification {

    public static Specification<Question> stemContainsTokens(String[] tokens) {
        return (root, query, cb) -> {
            if (tokens.length == 0) {
                return null;
            }
            javax.persistence.criteria.Predicate[] predicates = new javax.persistence.criteria.Predicate[tokens.length];
            for (int i = 0; i < tokens.length; i++) {
                predicates[i] = cb.like(root.get("stem"), "%" + tokens[i] + "%");
            }
            return cb.or(predicates);
        };
    }
}
